package view.component.weapon
{
	import enums.main.UISize;
	
	import feathers.controls.Button;
	import feathers.controls.Label;
	import feathers.controls.ScrollContainer;
	import feathers.controls.TabBar;
	
	import util.FG2FUGenerator;
	import util.WeaponUtil;
	
	import view.event.weapon.WeaponSearchViewEvent;
	
	/**
	 * 弩类武器搜索界面基类
	 * @author £iang
	 * 
	 */	
	public class BaseBowGunWeaponSearchView extends BaseWeaponSearchView
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 级别标题 */
		public var levelTitle:Label;
		/** 级别选项 */
		public var levelTabBar:TabBar;
		/** 限制解除标题 */
		public var limitBreakTitle:Label;
		/** 限制解除选项 */
		public var limitBreakTabBar:TabBar;
		/** 反动标题 */
		public var reactionTitle:Label;
		/** 反动选项 */
		public var reactionTabBar:TabBar;
		/** 装填速度标题 */
		public var reloadSpeedTitle:Label;
		/** 装填速度选项 */
		public var reloadSpeedTabBar:TabBar;
		/** 装填速度选项滚动容器 */
		public var reloadSpeedTabSC:ScrollContainer;
		/** 特殊弹种标题 */
		public var specialBulletTitle:Label;
		/** 特殊弹种选项 */
		public var specialBulletTabBar:TabBar;
		/** 特殊弹种选项滚动容器 */
		public var specialBulletTabSC:ScrollContainer;
		/** 洞数标题 */
		public var slotTitle:Label;
		/** 洞数选项 */
		public var slotTabBar:TabBar;
		/** 洞数选项滚动条容器 */
		public var slotTabSC:ScrollContainer;
		/** 结果排序标题 */
		public var sortTitle:Label;
		/** 结果排序选项 */
		public var sortTabBar:TabBar;
		/** 结果排序选项滚动条容器 */
		public var sortTabSC:ScrollContainer;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		/** 特殊弹种标题名 */
		protected var _specialBulletTitleName:String;
		/** 特殊弹种选择后的额外排序选项 */
		protected var _extraSortItemArr:Array;
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		override protected function initialize():void
		{
			super.initialize();
			
			var labelVec:Vector.<String> = new Vector.<String>();
		
			levelTitle = new Label();
			levelTitle.text = "级别：";
			mainSC.addChild( levelTitle );
			
			labelVec.push( "下位", "上位" );
			levelTabBar = createTabBar( labelVec );
			mainSC.addChild( levelTabBar );
			
			limitBreakTitle = new Label();
			limitBreakTitle.text = "限解：";
			mainSC.addChild( limitBreakTitle );
			
			labelVec.length = 0;
			labelVec.push( "全部", "可限解" );
			limitBreakTabBar = createTabBar( labelVec );
			mainSC.addChild( limitBreakTabBar );
			
			reactionTitle = new Label();
			reactionTitle.text = "反动：";
			mainSC.addChild( reactionTitle );
			
			labelVec.length = 0;
			labelVec.push( "全部", "中", "稍小", "小" );
			reactionTabBar = createTabBar( labelVec );
			mainSC.addChild( reactionTabBar );
			
			reloadSpeedTitle = new Label();
			reloadSpeedTitle.text = "装速：";
			mainSC.addChild( reloadSpeedTitle );
			
			labelVec.length = 0;
			labelVec.push( "全部", "稍慢", "普通", "稍快", "快" );
			reloadSpeedTabBar = createTabBar( labelVec );
			reloadSpeedTabSC = new ScrollContainer();
			mainSC.addChild( reloadSpeedTabSC );
			reloadSpeedTabSC.addChild( reloadSpeedTabBar );
		
			specialBulletTitle = new Label();
			specialBulletTitle.text = _specialBulletTitleName;
			mainSC.addChild( specialBulletTitle );
			
			labelVec.length = 0;
			
			var bulletLen:int = WeaponUtil.bulletData.length;
			
			labelVec.push( "全部" );
			
			for ( var i:int = 0; i < bulletLen; i ++ )
			{
				labelVec.push( WeaponUtil.getSimpleSpecialBulletName( i ) );
			}
			
			specialBulletTabBar = createTabBar( labelVec );
			specialBulletTabSC = new ScrollContainer();
			mainSC.addChild( specialBulletTabSC );
			specialBulletTabSC.addChild( specialBulletTabBar );
			
			slotTitle = new Label();
			slotTitle.text = "洞数：";
			mainSC.addChild( slotTitle );
			
			labelVec.length = 0;
			labelVec.push( "全部", "0洞", "1洞", "2洞", "3洞" );
			slotTabBar = createTabBar( labelVec );
			slotTabSC = new ScrollContainer();
			mainSC.addChild( slotTabSC );
			slotTabSC.addChild( slotTabBar );
			
			sortTitle = new Label();
			sortTitle.text = "排序：";
			mainSC.addChild( sortTitle );
			
			labelVec.length = 0;
			labelVec.push( "攻击力", "装速", "反动", "会心", "洞数" );
			sortTabBar = createTabBar( labelVec );
			sortTabSC = new ScrollContainer();
			mainSC.addChild( sortTabSC );
			sortTabSC.addChild( sortTabBar );
		}
		
		/**
		 * 绘制函数 
		 * 
		 */		
		override protected function draw():void
		{		
			super.draw();
			levelTitle.x = 20 * this.dpiScale;
			levelTabBar.x = 110 * this.dpiScale;
			limitBreakTitle.x = 20 * this.dpiScale;
			limitBreakTitle.y = 60 * this.dpiScale;
			limitBreakTabBar.x =  110 * this.dpiScale;
			limitBreakTabBar.y =  60 * this.dpiScale;
			reactionTitle.x = 20 * this.dpiScale;
			reactionTitle.y = 120 * this.dpiScale;
			reactionTabBar.x =  110 * this.dpiScale;
			reactionTabBar.y =  120 * this.dpiScale;
			reloadSpeedTitle.x = 20 * this.dpiScale;
			reloadSpeedTitle.y = 180 * this.dpiScale;
			reloadSpeedTabSC.x = 110 * this.dpiScale;
			reloadSpeedTabSC.y = 180 * this.dpiScale;
			reloadSpeedTabSC.width = UISize.MAIN_W - 130 * this.dpiScale;
			specialBulletTitle.x = 20 * this.dpiScale;
			specialBulletTitle.y = 240 * this.dpiScale;
			specialBulletTabSC.x = 110 * this.dpiScale;
			specialBulletTabSC.y = 240 * this.dpiScale;
			specialBulletTabSC.width = UISize.MAIN_W - 130 * this.dpiScale;
			slotTitle.x = 20 * this.dpiScale;
			slotTitle.y = 300 * this.dpiScale;
			slotTabSC.x =  110 * this.dpiScale;
			slotTabSC.y =  300 * this.dpiScale;
			slotTabSC.width = UISize.MAIN_W - 130 * this.dpiScale;
			sortTitle.x = 20 * this.dpiScale;
			sortTitle.y = 360 * this.dpiScale;
			sortTabSC.x =  110 * this.dpiScale;
			sortTabSC.y =  360 * this.dpiScale;
			sortTabSC.width = UISize.MAIN_W - 130 * this.dpiScale;
		}
		
		override public function dispatchSearchEvent():void
		{
			var weaponSearchEvent:WeaponSearchViewEvent = 
				new WeaponSearchViewEvent( WeaponSearchViewEvent.SEARCH );
			
			weaponSearchEvent.rank = levelTabBar.selectedIndex + 1;
			weaponSearchEvent.limitBreak = limitBreakTabBar.selectedIndex;
			weaponSearchEvent.reaction = reactionTabBar.selectedIndex + 1;
			weaponSearchEvent.reloadSpeed = reloadSpeedTabBar.selectedIndex + 2;
			weaponSearchEvent.specialBullet = specialBulletTabBar.selectedIndex - 1;
			weaponSearchEvent.slot = slotTabBar.selectedIndex - 1;
			weaponSearchEvent.sort = sortTabBar.selectedIndex;
			dispatchCommonEvent( weaponSearchEvent );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构函数 
		 * 
		 */		
		override public function dispose():void
		{
			levelTitle.dispose(); levelTitle = null;
			
			var button:Button;
			var k:int;
			
			for ( k = 0; k < levelTabBar.numChildren; k ++ )
			{
				if ( levelTabBar.getChildAt( k ) is Button )
				{
					button = levelTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			levelTabBar.dispose(); levelTabBar = null;
			limitBreakTitle.dispose(); limitBreakTitle = null;
			
			for ( k = 0; k < limitBreakTabBar.numChildren; k ++ )
			{
				if ( limitBreakTabBar.getChildAt( k ) is Button )
				{
					button = limitBreakTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			limitBreakTabBar.dispose(); limitBreakTabBar = null;
			reactionTitle.dispose(); reactionTitle = null;
			
			for ( k = 0; k < reactionTabBar.numChildren; k ++ )
			{
				if ( reactionTabBar.getChildAt( k ) is Button )
				{
					button = reactionTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			reactionTabBar.dispose(); reactionTabBar = null;
			reloadSpeedTitle.dispose(); reloadSpeedTitle = null;
			
			for ( k = 0; k < slotTabBar.numChildren; k ++ )
			{
				if ( reloadSpeedTabBar.getChildAt( k ) is Button )
				{
					button = reloadSpeedTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			reloadSpeedTabSC.dispose(); reloadSpeedTabSC = null;
			specialBulletTitle.dispose(); specialBulletTitle = null;
			
			for ( k = 0; k < slotTabBar.numChildren; k ++ )
			{
				if ( specialBulletTabBar.getChildAt( k ) is Button )
				{
					button = specialBulletTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			specialBulletTabSC.dispose(); specialBulletTabSC = null;
			slotTitle.dispose(); slotTitle = null;
			
			for ( k = 0; k < slotTabBar.numChildren; k ++ )
			{
				if ( slotTabBar.getChildAt( k ) is Button )
				{
					button = slotTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			slotTabSC.dispose(); slotTabSC = null;
			sortTitle.dispose(); sortTitle = null;
			
			for ( k = 0; k < sortTabBar.numChildren; k ++ )
			{
				if ( sortTabBar.getChildAt( k ) is Button )
				{
					button = sortTabBar.getChildAt( k ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			sortTabSC.dispose(); sortTabSC = null;
			super.dispose();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function BaseBowGunWeaponSearchView()
		{
			super();
		}
	}
}